package org.wanho.dao.impl;

import org.wanho.dao.UserDao;
import org.wanho.entity.User;
import org.wanho.jdbc.JdbcTemplate;
import org.wanho.mapper.UserMapper;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2024-12-03 15:04
 * Description：<描述>
 */
public class UserDaoImpl implements UserDao {

    private JdbcTemplate<User> jt = new JdbcTemplate<>();

    @Override
    public void insert(User user) {
        String sql = "insert into t_user (name, pwd, age, sex, height, birthday) values (?, ?, ?, ?, ?, ?)";
        jt.update(sql, user.getName(), user.getPwd(), user.getAge(), user.getSex(), user.getHeight(), user.getBirthday());
    }

    @Override
    public List<User> selectAll() {
        String sql = "select * from t_user";
        List<User> list = jt.query(sql, new UserMapper());
        return list;
    }

    @Override
    public void deleteById(int id) {
        String sql = "delete from t_user where id=?";
        jt.update(sql, id);
    }
}
